package product.api;

import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.hbase.HbaseTemplate;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import product.utils.DataUtils;

/**
 * Kafaka 消费端
 */
@Component
public class ConsumerListener {
	@Autowired
	private HbaseTemplate hbaseTemplate;

	final String tableName = "callLog";
	final String familyName = "info";

	@KafkaListener(topics = "callLog")
	public void onMessage(String message) {
		System.out.println(message);

		//		String message = "汪舶译,15530560288,许七,13768181465,1542629976337,9530";
		String[] values = message.split(",");

		String rowKey = DataUtils.genRowKey(values);

		//		String rowKey = DataUtils.nextLong(new Random(), 99999999999999L) + "";
		String[] columns = { "call", "call_name", "call2", "call2_name", "date_time", "date_time_ts" };
		for (int i = 0; i < columns.length; i++) {
			hbaseTemplate.put(tableName, rowKey, familyName, columns[i], Bytes.toBytes(values[i]));
		}
	}

}
